home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9062 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  92 lines

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Hiding a password
  5. Date: 05 Mar 1996 00:23:34 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar4172334@qcd.lanl.gov>
  8. References: <1996Feb29.224936.137160@forest> <4he620$qf2@hpbblb.bbn.hp.com>
  9.     <4hehmd$1fr@fnord.dfw.net>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: ftlgeuse@dfw.dfw.net's message of 4 Mar 1996 10:46:37 GMT
  14.  
  15. In article <4hehmd$1fr@fnord.dfw.net>
  16. ftlgeuse@dfw.dfw.net (Fetelgeuse) writes:
  17.  
  18. <snip>
  19. F: I wrote a function to do precisely the same thing. I made a function
  20. F: something like:
  21. F: char * GetString_NoEcho()
  22. F: {
  23. F:   char *temp;
  24. F:   int i=1;
  25. F:   while(temp[i-1]!=13) {
  26. F:     temp[i-1]=getch();  
  27. F:     i++;
  28. F:   }
  29. F:   temp[i]=0;
  30. F: }
  31. F: I haven't really thought that out real well so you might find that the 
  32. F: string index is the wrong value for any given character position but that
  33. F: would be easily fixed (if it is off, it would be off by 1 position) What 
  34. F: it should do is place the return value of a series of getch()'s
  35. into temp[0], 
  36. F: temp[1],temp[...], until the user enters [enter] and then where enter was 
  37. F: gets replaced by a null. Anyway, like I said the indexes may be off but 
  38. F: this way works when done properly.
  39.  
  40. Please test your solutions before you post them. I tried the following
  41. program: 
  42.  
  43. #include <stdio.h>
  44. char * GetString_NoEcho()
  45. {
  46.   char *temp;
  47.   int i=1;
  48.   while(temp[i-1]!=13) {
  49.     temp[i-1]=getch();  
  50.     i++;
  51.   }
  52.   temp[i]=0;
  53. }
  54. int main(void) {
  55.   char *pwd = GetString_NoEcho();
  56.   printf("%s\n",pwd);
  57.   return 0;
  58. }
  59.  
  60. When I tried to compile it, I get
  61.  
  62. j.c:3: warning: function declaration isn't a prototype
  63. j.c: In function `GetString_NoEcho':
  64. j.c:7: warning: implicit declaration of function `getch'
  65. j.c:4: warning: `temp' might be used uninitialized in this function
  66. j.c:11: warning: control reaches end of non-void function
  67. j.c: In function `main':
  68. j.c:13: warning: `pwd' might be used uninitialized in this function
  69. j.c:4: warning: `temp' might be used uninitialized in this function
  70. ld: Undefined symbol 
  71.    _getch 
  72.  
  73. and I get no executable.
  74.  
  75. Can you help me? Any idea what I am doing wrong? Should I change the
  76. i-1 to i*=+5 to get it to work?
  77.  
  78. If you haven't, please remember that when you post something that is
  79. wrong, you confuse a lot of other people. If you are merely trying to
  80. learn, please ask questions: do not pretend to know the answer when
  81. you don't.
  82.  
  83. Cheers
  84. Tanmoy
  85. --
  86. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  87. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  88. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  89. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  90. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  91. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  92.